package com.gi.product.utils;


import javax.annotation.PostConstruct;

public class EsUtil {

    //被@PostConstruct注释的方法将会在对应类注入到Spring后调用,确保index的生成
//    @PostConstruct
//    public void init() {
//        try {
//            if (client != null) {
//                client.close();
//            }
//            client = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, scheme)));
//            if (this.indexExist(INDEX_NAME)) {
//                return;
//            }
//            CreateIndexRequest request = new CreateIndexRequest(INDEX_NAME);
//            request.settings(Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 2));
//            request.mapping(CREATE_INDEX, XContentType.JSON);
//            CreateIndexResponse res = client.indices().create(request, RequestOptions.DEFAULT);
//            if (!res.isAcknowledged()) {
//                throw new RuntimeException("初始化失败");
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            System.exit(0);
//        }
//    }
}